home *** CD-ROM | disk | FTP | other *** search
/ Champak 140 / (Vol 140) Sep 19 2011.iso / Games / theLifeArk.swf / scripts / __Packages / prop / pz1.as < prev    next >
Encoding:
Text File  |  2011-09-19  |  6.4 KB  |  197 lines

  1. class prop.pz1 extends MovieClip
  2. {
  3.    var cq;
  4.    var rq;
  5.    var usedTimes;
  6.    var usedTimesMax;
  7.    var clockwise;
  8.    var shapeSqc1;
  9.    var shapeSqc2;
  10.    var firstDrct;
  11.    var answerR;
  12.    var answerC;
  13.    var aAgl;
  14.    var aBtnNum;
  15.    function pz1()
  16.    {
  17.       super();
  18.       this.cq = 3;
  19.       this.rq = 3;
  20.       this.usedTimes = 0;
  21.       this.usedTimesMax = 2;
  22.       this.clockwise = true;
  23.       this.shapeSqc1 = new Array();
  24.       this.shapeSqc1.push({shape:"square",ranNum:0});
  25.       this.shapeSqc1.push({shape:"triangle",ranNum:0});
  26.       this.shapeSqc1.push({shape:"circle",ranNum:0});
  27.       this.shapeSqc2 = new Array();
  28.       this.shapeSqc2.push({shape:"square",ranNum:0});
  29.       this.shapeSqc2.push({shape:"star",ranNum:0});
  30.       this.shapeSqc2.push({shape:"circle",ranNum:0});
  31.       this.resetMe();
  32.    }
  33.    function resetMe()
  34.    {
  35.       var _loc8_ = 0;
  36.       while(_loc8_ < this.rq)
  37.       {
  38.          var _loc2_ = 0;
  39.          while(_loc2_ < this.cq)
  40.          {
  41.             this["r" + _loc8_ + "c" + _loc2_].gotoAndStop("normal");
  42.             this["r" + _loc8_ + "c" + _loc2_].ctt2._x = this["r" + _loc8_ + "c" + _loc2_].ctt2._y = 0;
  43.             _loc2_ = _loc2_ + 1;
  44.          }
  45.          _loc8_ = _loc8_ + 1;
  46.       }
  47.       _loc8_ = 0;
  48.       while(_loc8_ < 4)
  49.       {
  50.          this["btn" + _loc8_].ctt2._x = this["btn" + _loc8_].ctt2._y = 0;
  51.          this["btn" + _loc8_].onPress = this.btnPrsW;
  52.          _loc8_ = _loc8_ + 1;
  53.       }
  54.       var _loc12_ = false;
  55.       this.clockwise = 1 * Math.random() <= 0.5 ? false : true;
  56.       this.firstDrct = Math.floor(4 * Math.random());
  57.       this.answerR = Math.floor(this.rq * Math.random());
  58.       this.answerC = Math.floor(this.cq * Math.random());
  59.       this["r" + this.answerR + "c" + this.answerC].gotoAndStop("tar");
  60.       _loc8_ = 0;
  61.       while(_loc8_ < this.rq)
  62.       {
  63.          this.shapeSqc1[_loc8_].ranNum = 1 * Math.random();
  64.          this.shapeSqc2[_loc8_].ranNum = 1 * Math.random();
  65.          _loc8_ = _loc8_ + 1;
  66.       }
  67.       this.shapeSqc1.sortOn("ranNum",Array.NUMERIC);
  68.       this.shapeSqc2.sortOn("ranNum",Array.NUMERIC);
  69.       _loc8_ = 0;
  70.       while(_loc8_ < this.rq)
  71.       {
  72.          if(this.answerR != _loc8_ && !_loc12_)
  73.          {
  74.             _loc12_ = true;
  75.             var _loc11_ = Math.floor(this.cq * Math.random());
  76.             this["r" + _loc8_ + "c" + _loc11_].gotoAndStop("mask");
  77.          }
  78.          var _loc10_ = this.normalDeg((this.firstDrct + _loc8_) * 90);
  79.          if(this.answerR == _loc8_)
  80.          {
  81.             this.aAgl = _loc10_;
  82.          }
  83.          var _loc13_ = Math.sin(_loc10_ * 3.141592653589793 / 180);
  84.          var _loc14_ = Math.cos(_loc10_ * 3.141592653589793 / 180);
  85.          _loc13_ = Math.abs(_loc13_) >= 0.0001 ? _loc13_ : 0;
  86.          _loc14_ = Math.abs(_loc14_) >= 0.0001 ? _loc14_ : 0;
  87.          _loc2_ = 0;
  88.          while(_loc2_ < this.cq)
  89.          {
  90.             this["r" + _loc8_ + "c" + _loc2_].ctt1.gotoAndStop(this.shapeSqc1[_loc8_].shape);
  91.             this["r" + _loc8_ + "c" + _loc2_].ctt2.gotoAndStop(this.shapeSqc2[_loc8_].shape);
  92.             this["r" + _loc8_ + "c" + _loc2_].ctt2._x += 20 * _loc2_ * _loc14_;
  93.             this["r" + _loc8_ + "c" + _loc2_].ctt2._y += 20 * _loc2_ * _loc13_;
  94.             _loc2_ = _loc2_ + 1;
  95.          }
  96.          _loc8_ = _loc8_ + 1;
  97.       }
  98.       _loc8_ = 0;
  99.       while(_loc8_ < 4)
  100.       {
  101.          this["btn" + _loc8_].ctt1.gotoAndStop(this.shapeSqc1[this.answerR].shape);
  102.          this["btn" + _loc8_].ctt2.gotoAndStop(this.shapeSqc2[this.answerR].shape);
  103.          _loc8_ = _loc8_ + 1;
  104.       }
  105.       var _loc3_ = new Array();
  106.       _loc8_ = 0;
  107.       while(_loc8_ < 4)
  108.       {
  109.          var _loc6_ = false;
  110.          while(!_loc6_)
  111.          {
  112.             var _loc9_ = this.normalDeg(Math.floor(Math.random() * 4) * 90);
  113.             var _loc7_ = 1 + Math.floor(Math.random() * 2);
  114.             var _loc4_ = false;
  115.             var _loc5_ = false;
  116.             if(_loc9_ == this.aAgl && _loc7_ == this.answerC)
  117.             {
  118.                _loc5_ = true;
  119.             }
  120.             _loc2_ = 0;
  121.             while(_loc2_ < _loc3_.length)
  122.             {
  123.                if(_loc3_[_loc2_].aglWrong == _loc9_ && _loc3_[_loc2_].cWrong == _loc7_)
  124.                {
  125.                   _loc4_ = true;
  126.                }
  127.                _loc2_ = _loc2_ + 1;
  128.             }
  129.             if(!_loc4_ && !_loc5_)
  130.             {
  131.                _loc3_.push({aglWrong:_loc9_,cWrong:_loc7_});
  132.                _loc6_ = true;
  133.             }
  134.          }
  135.          _loc13_ = Math.sin(_loc9_ * 3.141592653589793 / 180);
  136.          _loc14_ = Math.cos(_loc9_ * 3.141592653589793 / 180);
  137.          _loc13_ = Math.abs(_loc13_) >= 0.0001 ? _loc13_ : 0;
  138.          _loc14_ = Math.abs(_loc14_) >= 0.0001 ? _loc14_ : 0;
  139.          this["btn" + _loc8_].ctt2._x += 20 * _loc7_ * _loc14_;
  140.          this["btn" + _loc8_].ctt2._y += 20 * _loc7_ * _loc13_;
  141.          _loc8_ = _loc8_ + 1;
  142.       }
  143.       this.aBtnNum = Math.floor(4 * Math.random());
  144.       _loc13_ = Math.sin(this.aAgl * 3.141592653589793 / 180);
  145.       _loc14_ = Math.cos(this.aAgl * 3.141592653589793 / 180);
  146.       _loc13_ = Math.abs(_loc13_) >= 0.0001 ? _loc13_ : 0;
  147.       _loc14_ = Math.abs(_loc14_) >= 0.0001 ? _loc14_ : 0;
  148.       this["btn" + this.aBtnNum].ctt2._x = 20 * this.answerC * _loc14_;
  149.       this["btn" + this.aBtnNum].ctt2._y = 20 * this.answerC * _loc13_;
  150.       this["btn" + this.aBtnNum].onPress = this.btnPrsR;
  151.    }
  152.    function normalDeg(r)
  153.    {
  154.       if(r >= 180)
  155.       {
  156.          r -= 360;
  157.       }
  158.       if(r <= -180)
  159.       {
  160.          r += 360;
  161.       }
  162.       return r;
  163.    }
  164.    function btnPrsW()
  165.    {
  166.       this._parent.prsWrong();
  167.    }
  168.    function btnPrsR()
  169.    {
  170.       this._parent.prsRight();
  171.    }
  172.    function prsWrong()
  173.    {
  174.       this.usedTimes = this.usedTimes + 1;
  175.       if(this.usedTimes > 2)
  176.       {
  177.          _global.scene.pwSource.gotoAndStop("broken");
  178.          this._visible = false;
  179.       }
  180.       _global.ctn.sndCtrl.playSound("snd_pzWrong");
  181.       this._visible = false;
  182.    }
  183.    function prsRight()
  184.    {
  185.       trace("choose right");
  186.       _global.ctn.sndCtrl.playSound("snd_pzRight");
  187.       _global.scene.pwSource.coverAni.play();
  188.       if(!_global.scene.pzScoreOver)
  189.       {
  190.          _global.scene.pzScoreOver = true;
  191.          _global.ctn.game.addScore(300,500,0,60);
  192.          _global.ctn.game.addScore(45,Math.round(100 * (1 - this.usedTimes / this.usedTimesMax)),0,60);
  193.       }
  194.       this.unloadMovie();
  195.    }
  196. }
  197.